#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int left = 1;
        int right = 1;
        vector<int> ans = vector<int>(nums.size());
        for (int i = 0; i < nums.size(); i++) {
            ans[i] = left;
            left *= nums[i];
        }
        for (int i = nums.size() - 1; i >= 0; i--) {
            ans[i] *= right;
            right *= nums[i];
        }
        return ans;
    }
};

int main() {
    vector<int> input = {1, 2, 3, 4};
    Solution solution;
    vector<int> output = solution.productExceptSelf(input);
    for (int item : output) {
        cout << item << endl;
    }
    return 0;
}
